home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABUFSSpecs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  6.8 KB  |  247 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was created & modified by George (ty) Tempel in 
  8.     connection with TopSoft, Inc. from Apple DTS source code:
  9.     
  10.         Apple Macintosh Developer Technical Support
  11.     
  12.         A collection of useful high-level File Manager routines.
  13.     
  14.         by Jim Luther, Apple Developer Technical Support
  15.     
  16.         from File:        MoreFilesExtras.c
  17.     
  18.         Copyright © 1992-1994 Apple Computer, Inc.
  19.         All rights reserved.
  20.     
  21.         You may incorporate this sample code into your applications without
  22.         restriction, though the sample code has been provided "AS IS" and the
  23.         responsibility for its operation is 100% yours.  However, what you are
  24.         not permitted to do is to redistribute the source as "DSC Sample Code"
  25.         after having made changes. If you're going to re-distribute the source,
  26.         we require that you make it clear in the source that the code was
  27.         descended from Apple Sample Code, but that you've made changes.
  28.  
  29.     See the Modification History for more details.
  30.  
  31. Product
  32.     About Box
  33.  
  34. FILE
  35.     ABUFSSpecs.c
  36.  
  37. NAME
  38.     ABUFSSpecs.c, part of the ABox project source code,
  39.     responsible for utility handling the AboutBox FSSpecs stuff.
  40.  
  41. DESCRIPTION
  42.     This file contains methods for the ABUFSSpecs class.
  43.     
  44. DEVELOPED BY
  45.     George (ty) Tempel                ttempel@monmouth.com
  46.     All code in this file, and its associated header file was
  47.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  48.     "FilterTop" application development, except where noted.
  49.  
  50. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  51.      Please consult this person for any changes or suggestions to this file.
  52.  
  53. MODIFICATION HISTORY
  54.  
  55.     dd mmm yy    -    xxx    -    patchxx: description of patch
  56.     15 july 94    -    ty    -    Initial Version Created
  57.     20-july-94    -    ty    -    initial version released
  58.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  59.                             release and the associated Universal Headers from Apple:
  60.                             most methods that returned references now have "Ref" at
  61.                             the end of their methods names to prevent possible collisions
  62.                             with datatypes and classes of the same name (older versions
  63.                             of the compiler didn't have a problem with this).
  64.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  65.                             query methods
  66.  
  67. */
  68.  
  69. /*===========================================================================*/
  70.  
  71. /*======= Segmentation directives ========*/
  72. #ifdef USE_MANUAL_SEGMENTATION
  73. #pragma segment ty
  74. #endif
  75.  
  76. /*============ Header files ==============*/
  77.  
  78. #include    "ABUFSSpecs.h"
  79.  
  80.  
  81. /*=============== Globals ================*/
  82.  
  83. /*================ CODE ==================*/
  84.  
  85.  
  86.  
  87. /*========================= ABUFSSpecs::ABUFSSpecs =================================*/
  88. ABUFSSpecs::ABUFSSpecs (void)
  89. {
  90.     //    do nothing!
  91. } // end ABUFSSpecs
  92.  
  93.  
  94.  
  95.  
  96. /*========================= ABUFSSpecs::~ABUFSSpecs =================================*/
  97. ABUFSSpecs::~ABUFSSpecs (void)
  98. {
  99.     //    do nothing!
  100. } // end ~ABUFSSpecs
  101.  
  102.  
  103.  
  104.  
  105.  
  106. /*========================= ABUFSSpecs::GetDirID =================================*/
  107. pascal    OSErr    
  108. ABUFSSpecs::GetDirID(short vRefNum,
  109.                      long dirID,
  110.                      StringPtr name,
  111.                      long *theDirID,
  112.                      Boolean *isDirectory)
  113. {
  114.     CInfoPBRec pb;
  115.     OSErr error;
  116.  
  117.     pb.hFileInfo.ioNamePtr = name;
  118.     pb.hFileInfo.ioVRefNum = vRefNum;
  119.     pb.hFileInfo.ioDirID = dirID;
  120.     pb.hFileInfo.ioFDirIndex = 0;    // use ioNamePtr and ioDirID
  121.     error = ::PBGetCatInfoSync(&pb);
  122.     *theDirID = pb.hFileInfo.ioDirID;
  123.     *isDirectory = (pb.hFileInfo.ioFlAttrib & 0x10) != 0;
  124.     return (error);
  125. }
  126.  
  127.  
  128.  
  129. /*========================= ABUFSSpecs::DirIDFromFSSpec =============================*/
  130.  
  131. pascal    OSErr    
  132. ABUFSSpecs::DirIDFromFSSpec(const FSSpec *spec,
  133.                             long *theDirID,
  134.                             Boolean *isDirectory)
  135. {
  136.     return (ABUFSSpecs::GetDirID(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  137.                                 theDirID, isDirectory));
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144. /*========================= ABUFSSpecs::DetermineVRefNum ============================*/
  145.  
  146. pascal    OSErr
  147. ABUFSSpecs::DetermineVRefNum(StringPtr pathname,
  148.                              short vRefNum,
  149.                              short *realVRefNum)
  150. {
  151.     HParamBlockRec pb;
  152.     Str255 tempPathname;
  153.     OSErr error;
  154.  
  155.     pb.volumeParam.ioVRefNum = vRefNum;
  156.     if (pathname == nil) 
  157.     {
  158.         pb.volumeParam.ioNamePtr = nil;
  159.         pb.volumeParam.ioVolIndex = 0;        // use ioVRefNum only
  160.     } else {
  161.         ::BlockMove ((Ptr)pathname, (Ptr)tempPathname, *pathname + 1);
  162.         pb.volumeParam.ioNamePtr = (StringPtr)tempPathname;    // use the copy so original isn't trashed
  163.         pb.volumeParam.ioVolIndex = -1;    // use ioNamePtr/ioVRefNum combination
  164.     }
  165.     error = ::PBHGetVInfoSync(&pb);
  166.     if (realVRefNum)
  167.         *realVRefNum = pb.volumeParam.ioVRefNum;
  168.     return (error);
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175. /*========================= ABUFSSpecs::GetDirItems ============================*/
  176.  
  177. pascal    OSErr
  178. ABUFSSpecs::GetDirItems(short vRefNum,
  179.                         long dirID,
  180.                         StringPtr name,
  181.                         Boolean getFiles,
  182.                         Boolean getDirectories,
  183.                         FSSpecPtr items,
  184.                         short reqItemCount,
  185.                         short *actItemCount,
  186.                         short *itemIndex) // start with 1, then use what's returned
  187. {
  188.     CInfoPBRec pb;
  189.     OSErr error = noErr;
  190.     long theDirID;
  191.     Boolean isDirectory;
  192.     FSSpec *endItemsArray = items + reqItemCount;
  193.  
  194.     // NOTE: If I could be sure that the caller passed a real vRefNum and real directory 
  195.     // to this routine, I could rip out calls to DetermineVRefNum and GetDirID and this 
  196.     // routine would be much faster because of the overhead of DetermineVRefNum and 
  197.     // GetDirID and because GetDirID blows away the directory index hint the Macintosh 
  198.     // file system keeps for indexed calls. I can't be sure, so for maximum throughput, 
  199.     // pass a big array of FSSpecs so you can get the directory's contents with few calls 
  200.     // to this routine. 
  201.     
  202.     // get the real volume reference number 
  203.     error = ABUFSSpecs::DetermineVRefNum(name, vRefNum, &pb.hFileInfo.ioVRefNum);
  204.     if (error != noErr)
  205.         return (error);
  206.     
  207.     // and the real directory ID of this directory (and make sure it IS a directory 
  208.     error = ABUFSSpecs::GetDirID(vRefNum, dirID, name, &theDirID, &isDirectory);
  209.     if (error != noErr)
  210.         return (error);
  211.     else if (!isDirectory)
  212.         return (dirNFErr);
  213.  
  214.  
  215.     *actItemCount = 0;
  216.     for (; (items < endItemsArray) && (error == noErr); )
  217.     {
  218.         pb.hFileInfo.ioNamePtr = (StringPtr) &items->name;
  219.         pb.hFileInfo.ioDirID = theDirID;
  220.         pb.hFileInfo.ioFDirIndex = *itemIndex;
  221.         error = ::PBGetCatInfoSync(&pb);
  222.         if (error == noErr)
  223.         {
  224.             items->parID = pb.hFileInfo.ioFlParID;    // return item's parID 
  225.             items->vRefNum = pb.hFileInfo.ioVRefNum;    // return item's vRefNum 
  226.             ++*itemIndex;    // prepare to get next item in directory 
  227.             
  228.             if (pb.hFileInfo.ioFlAttrib & 0x10) {
  229.                 if (getDirectories) {
  230.                     ++*actItemCount; // keep this item 
  231.                     ++items; // point to next item 
  232.                 }
  233.             }
  234.             else {
  235.                 if (getFiles) {
  236.                     ++*actItemCount; // keep this item 
  237.                     ++items; // point to next item 
  238.                 }
  239.             }
  240.         }
  241.     }
  242.     return (error);
  243. }
  244.  
  245.  
  246. //    end of file.
  247.